package com.ultrapower.ctool.core;

/**
 * Created by club on 2017/5/10.
 */


import android.content.Context;
import android.database.Cursor;
import android.widget.SimpleCursorAdapter;

import com.ultrapower.ctool.utils.DBHelper;
import com.ultrapower.ctool.utils.JydwHelper;

/**
 *
 * @author lai_zs
 * @date：2012-2-16 下午3:49:25
 */
public class JywgAutoCompleteAdater extends SimpleCursorAdapter {

    private JydwHelper dbHelper = null;
    private Context context;
    // 查询字段
    private String queryField;

    public JywgAutoCompleteAdater(Context context, int layout, Cursor c, String from, int to) {
        super(context, layout, c, new String[] { from }, new int[] { to });
        this.context = context;
        this.queryField = from;
    }

    /**
     * 动态查询数据库
     */
    @Override
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
        System.out.println("--------------"+constraint);
        if (constraint != null) {
            return getDbHelper().query((String) constraint);
        } else {
            return null;
        }
    }

    /**
     * 这里设置在弹出的提示列表中点击某一项后的返回值,返回值将被显示在文本框中
     */
    @Override
    public CharSequence convertToString(Cursor cursor) {
        return cursor.getString(cursor.getColumnIndex("cn"));
        //return  new RegisterRolePirVO(cursor.getString(cursor.getColumnIndex("_id")), cursor.getString(cursor.getColumnIndex("cn"))).toString();
    }

    public JydwHelper getDbHelper() {
        if (dbHelper == null) {
            dbHelper = new JydwHelper(this.context);
        }
        return dbHelper;
    }

}
